#include <rtthread.h>
#include <unistd.h>

static void acmwr(int argc, char **argv)
{
    int fd;
    int cnt = 30;
    char *buf;
    int ret;

    if ((buf = rt_malloc(64)) == RT_NULL)
    {
        rt_kprintf("no mem\n");
        return;
    }

    fd = open(":dev/ttyACM0", O_RDWR);
    if (fd < 0)
    {
        rt_kprintf("open fail\n");
        goto _out;
    }

    while (cnt --)
    {
        ret = write(fd, "AT\r\n", 4);
        if (ret < 0)
        {
            rt_kprintf("write fail\n");
            break;
        }
        ret = read(fd, buf, 63);
        if (ret <= 0)
        {
            rt_kprintf("read fail\n");
            break;            
        }

        buf[ret] = 0;
        rt_kprintf(buf);
        rt_thread_mdelay(1000);
    }
    close(fd);

_out:
    rt_free(buf);
}
MSH_CMD_EXPORT(acmwr, acm Write and Read);
